package com.imooc.miaosha.dao;

import com.imooc.miaosha.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

/**
 * @author simple
 * @version 1.0
 * @date 2018/6/14 00:30
 */
@Mapper
public interface UserDao {
    /**
     * 根据id获取用户
     *
     * @param id id
     * @return User
     */
    @Select("select * from user where id=#{id} limit 1")
    User getById(@Param("id") long id);

    /**
     * 根据手机号获取用户
     *
     * @param mobile mobile
     * @return User
     */
    @Select("select * from user where mobile=#{mobile} limit 1")
    User getByMobile(@Param("mobile") String mobile);

    /**
     * 插入一条用户记录
     *
     * @param user User
     * @return int
     */
    @Insert("insert into user (id, name) values (#{id}, #{name})")
    int insert(User user);
}
